import 'package:my_app/global/global.dart';
import 'package:my_app/service/http/http.dart';

class ApiService {
  static String url = GlobalData.apiUrl;
  static String mapsuid = GlobalData.mapsId;
  // 获取单独
  static void getSingleData() async {
    var sql =
        "MAPS_FUNC_QR_DIRECT_GET('QR1123581000022022200160000000000','4550020200705','','','','')";
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    print(data);
    return data;
  }

  // 获取url地址
  static getApiUrl() async {
    String sql = "MAPS_FUNC_QRWS_ADDR_GET('','','','','','')";
    var data = await HttpRequest.postString(
        "http://43.247.102.196:10185/User_MAPS_MUJI_POS_V3_DEV_Rest_app_ws/rest/api/" +
            "func/string",
        sql,
        mapsuid);
    return data;
  }

  // 登录
  /*parms{人员编号，密码 }*/
  /*return {角色编号,角色名称,模块编号,人员编号,人员名称,厂商编号,厂商名称}*/
  static login(String userName, String password) async {
    String sql = "MAPS_FUNC_QR_STAFFAUTH_GET('$userName','$password')";
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 生成IF_SN
  /*params {公司ID，分公司ID，部门ID，用户ID，嵌入的自定义字符串，生成器ID}*/
  /*return {申请编号}*/
  static getIfsnData() async {
    String sql = "MAPS_FUNC_DATA_NUMBER_MAKER('*','*','*','*','*','IF_SN')";
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data; //
  }

  // 检查空白异常
  /*params{批次号,二维码编号头,二维码编号尾,商品编号,赋码人,赋码时间,批次行号}*/
  /*return{-1/-2开头执行失败 1开头执行成功}*/
  static checkGoodsData(
      String ifsn,
      String qrcode,
      String qrEndcode,
      String goodscode,
      String charName,
      String dateTime,
      String lineNum) async {
    String sql =
        "MAPS_FUNC_QR_CODE_PDA_INPUT('$ifsn','$qrcode','$qrEndcode', '$goodscode', '$charName', '$dateTime', '$lineNum')";
    print("checkGoodsData");
    print(sql);
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data;
  }

  // 批量检查空白异常
  // params{多个 checkGoodsData sql + ";"拼接}
  static checkAllGoodsData(String sql) async {
    var data =
        await HttpRequest.postString(url + "batchfunc/string", sql, mapsuid);
    return data;
  }

  // 检查二维码是否存在
  /*params{批次号}*/
  /*return{批次行号,标志位,异常信息}*/
  static checkQrData(String ifsn) async {
    String sql = "MAPS_FUNC_QR_DR_CHECK('$ifsn')";
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 扫描完毕
  /*params{批次号,供应商}*/
  /*return{-1开头执行失败,1开头执行成功}*/
  static sanDone(String ifsn, String vendorID) async {
    String sql = "MAPS_FUNC_QR_CODE_END('$ifsn','$vendorID')";
    print(sql);
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data;
  }

  // 本次赋码列表
  /*params{接口序列号,二维码编号,商品编号,效期,生产日期,商品名称,状态,开始数,结束数} */
  /*return{二维码编号,卷数,商品条码,绑定日期,生产日期,有效期,质检报告,状态,总数} */
  static nowQrListData(String ifsn, String startNum, String endNum,
      [String qr = '',
      String goodsCode = '',
      String validity = '',
      String productionDate = '',
      String goodsName = '',
      String status = '']) async {
    String sql =
        "MAPS_FUNC_QR_JUMP_GET('$ifsn','$qr','$goodsCode','$validity','$productionDate','$goodsName','$status','$startNum','$endNum')";
    print(sql);
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 首页进入赋码列表
  /*params{接口序列号,二维码编号,商品编号,效期,效期单位，生产日期,商品名称,状态,开始数,结束数} */
  /*return{二维码编号,卷数,商品条码,绑定日期,生产日期,有效期,质检报告,状态,总数} */
  static allQrListData(String startNum, String endNum, String staffid,
      [String qr = '',
      String goodsCode = '',
      String validity = '',
      String validityUnit = '',
      String goodsName = '',
      String status = '']) async {
    String sql =
        "MAPS_FUNC_QR_DIRECT_GET('$qr','$goodsCode','$validity','$validityUnit','$goodsName','$status','$startNum','$endNum','$staffid')";
    print("____________allQrListData______________");
    print(sql);
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 详情页面数据获取
  /*params{二维码编号} */
  /*return{二维码编号,生产（赋码时间）,供应商编号,供应商名称,商品条码,商品名称,单位,规格,产地,保质期,质检报告,生产日期,到期日期} */
  static getDetailData(String qrCode) async {
    String sql = "MAPS_FUNC_QR_ITEM_GET('$qrCode')";
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 保存二维码详情
  /*params{二维码编号,商品编号，单位,规格,产地,保质期,生产日期,到期日期,质检报告,保质期单位} */
  /*return{-1开头执行失败,1开头执行成功} */
  static saveDetailData(
      String qr,
      String goods,
      String unit,
      String norm,
      String generateLocation,
      String shelfLife,
      String productionDate,
      String maturityDate,
      String checkImg,
      String shelfLifeUnit) async {
    String sql =
        "MAPS_FUNC_QR_ITEM_BATCH('$qr','$goods','$unit','$norm','$generateLocation','$shelfLife','$productionDate','$maturityDate','$checkImg','$shelfLifeUnit')";
    print("保存二维码详情");
    print(sql);
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data;
  }

  // 修改商品条码
  /*params{商品编号 } */
  /*return{商品条码,商品名称,单位,规格,产地,保质期} */
  static changeGoodsCode(String goods,
      [String supplierNumber = "", String productionDate = ""]) async {
    String sql =
        "MAPS_FUNC_ITEM_GET('$goods','$supplierNumber','$productionDate')";
    print("修改商品条码");
    print(sql);
    var data = await HttpRequest.postList(url + "func/list", sql, mapsuid);
    return data;
  }

  // 获取商品图片
  static getDetailImg(String imgID) async {
    String sql = "MAPS_FUNC_QR_REPORT_GET('${GlobalData.mapsId}','$imgID')";
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data;
  }

  // 删除数据
  /*params{批次号,二维码编号头,二维码编号尾,商品编号,赋码人,赋码时间,批次行号}*/
  /*return{-1/-2开头执行失败 1开头执行成功}*/
  static delGoodsData(
      String ifsn,
      String qrcode,
      String qrEndcode,
      String goodscode,
      String charName,
      String dateTime,
      String lineNum) async {
    String sql =
        "MAPS_FUNC_QR_CODE_PDA_INPUT('$ifsn','$qrcode','$qrEndcode', '$goodscode', '$charName', '$dateTime', '$lineNum','1')";
    print("delGoodsData");
    print(sql);
    var data = await HttpRequest.postString(url + "func/string", sql, mapsuid);
    return data;
  }
}
